//
//  EditAddreSOView.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/25.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "EditAddreSOView.h"
#import "CommonMacro.h"

@interface EditAddreSOView ()
@property (nonatomic,strong) UIView *reciveAddreView;
@property (nonatomic,strong) UIView *detailLabel;
@property (nonatomic,strong) UILabel *defaultLabel;
@property (nonatomic,strong) UIButton *changeAddreButton;
@property (nonatomic,strong) UILabel *bigNameLabel;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *cityLabel;
@property (nonatomic,strong) UILabel *zipCodeLabel;
@property (nonatomic,strong) UILabel *genderLabel;
@property (nonatomic,strong) UILabel *phoneNumLabel;
@property (nonatomic,strong) UILabel *addressLabel;

@end

@implementation EditAddreSOView

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self createSubview];
    }
    return self;
}

- (void)createSubview
{
    //2.默认收货地址
    self.reciveAddreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.4)];
    //    reciveAddreView.backgroundColor = [UIColor cyanColor];
    [self addSubview:self.reciveAddreView];
    
    //2.1默认地址
    self.defaultLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, self.frame.size.width*0.4, self.reciveAddreView.frame.size.height*0.1)];
    //    defaultLabel.backgroundColor = [UIColor redColor];
    self.defaultLabel.text = @"默认收货地址：";
    self.defaultLabel.textColor = UIColorWithRGBA(135, 135, 135, 1);
    self.defaultLabel.font = [UIFont systemFontOfSize:16];
    [self.reciveAddreView addSubview:self.defaultLabel];
    
    //2.2具体内容
    self.detailLabel = [[UIView alloc] initWithFrame:CGRectMake(self.defaultLabel.frame.origin.x, self.defaultLabel.frame.origin.y+self.defaultLabel.frame.size.height, SCREEN_WIDTH-self.defaultLabel.frame.origin.x*2, self.reciveAddreView.frame.size.height*0.65)];
    [self.reciveAddreView addSubview:self.detailLabel];
    self.detailLabel.backgroundColor = UIColorWithRGBA(252, 237, 163, 1);
//    detailLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"收货人底框"]];
    self.detailLabel.layer.cornerRadius = 3;
    self.detailLabel.clipsToBounds = YES;
    self.detailLabel.layer.borderColor = UIColorWithRGBA(201, 196, 183, 1).CGColor;
    self.detailLabel.layer.borderWidth = 1;
    [self initWithSubviews];
    
    //2.3更换收货地址
    self.changeAddreButton = [[UIButton alloc] initWithFrame:CGRectMake(self.detailLabel.frame.size.width*0.5, self.detailLabel.frame.size.height+self.detailLabel.frame.origin.y+10, self.detailLabel.frame.size.width*0.5, self.defaultLabel.frame.size.height*1.2)];
    [self.changeAddreButton setTitle:@"更换收货地址" forState:UIControlStateNormal];
    [self.changeAddreButton setTitleColor:UIColorWithRGBA(249, 170, 77, 1) forState:UIControlStateNormal];
    self.changeAddreButton.layer.cornerRadius = 3;
    self.changeAddreButton.clipsToBounds = YES;
    self.changeAddreButton.layer.borderWidth = 1;
    self.changeAddreButton.layer.borderColor = UIColorWithRGBA(201, 201, 201, 1).CGColor;
    [self.reciveAddreView addSubview:self.changeAddreButton];
    [self.changeAddreButton addTarget:self action:@selector(editAddress) forControlEvents:UIControlEventTouchUpInside];
}

#pragma  mark 具体内部摆件
- (void)initWithSubviews
{
    CGFloat margginX = 10;
    CGFloat margginY = 5;
    CGFloat labelX = 10;
    CGFloat labelY = 5;
    CGFloat font = 14;
    CGFloat labelH = (self.detailLabel.frame.size.height-labelY-4*margginY)/4;
    CGFloat labelW = (self.detailLabel.frame.size.width-labelX-2*margginX)/3;
    //1.大名
    self.bigNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(margginX, margginY, labelW, labelH)];
    [self.detailLabel addSubview:self.bigNameLabel];
    self.bigNameLabel.text = @"Linda";
    self.bigNameLabel.textColor = UIColorWithRGBA(248, 136, 40, 1);
    self.bigNameLabel.font = [UIFont boldSystemFontOfSize:20];
    
    //2.姓名
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelX, self.bigNameLabel.frame.size.height+margginY, labelW, labelH)];
    [self.detailLabel addSubview:self.nameLabel];
    self.nameLabel.text = [NSString stringWithFormat:@"姓名：Linda"];
    self.nameLabel.textColor = UIColorWithRGBA(248, 162, 51, 1);
    self.nameLabel.font = [UIFont boldSystemFontOfSize:font];
    
    //3.城市
    self.cityLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLabel.frame.size.width+self.nameLabel.frame.origin.x+margginX, labelY+labelH, labelW, labelH) ];
    [self.detailLabel addSubview:self.cityLabel];
    self.cityLabel.text = [NSString stringWithFormat:@"城市：杭州"];
    self.cityLabel.textColor = UIColorWithRGBA(248, 162, 51, 1);
    self.cityLabel.font = [UIFont boldSystemFontOfSize:font];

    //4.邮编
    self.zipCodeLabel = [[UILabel alloc] initWithFrame:CGRectMake((labelW+margginX)*2, labelH+labelY, labelW, labelH)];
    [self.detailLabel addSubview:self.zipCodeLabel];
    self.zipCodeLabel.text = [NSString stringWithFormat:@"邮编：325151"];
    self.zipCodeLabel.textColor = UIColorWithRGBA(248, 162, 51, 1);
    self.zipCodeLabel.font = [UIFont boldSystemFontOfSize:font];

    //5.性别
    self.genderLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelX, (labelH+margginY)*2+labelY, labelW, labelH)];
    [self.detailLabel addSubview:self.genderLabel];
    self.genderLabel.text = [NSString stringWithFormat:@"性别：女"];
    self.genderLabel.textColor = UIColorWithRGBA(248, 162, 51, 1);
    self.genderLabel.font = [UIFont boldSystemFontOfSize:font];

    //6.手机号
    self.phoneNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelX+labelW+margginX, (labelH+margginY)*2+labelY, labelW*2, labelH)];
    [self.detailLabel addSubview:self.phoneNumLabel];
    self.phoneNumLabel.text = [NSString stringWithFormat:@"手机：18356153208"];
    self.phoneNumLabel.textColor = UIColorWithRGBA(248, 162, 51, 1);
    self.phoneNumLabel.font = [UIFont boldSystemFontOfSize:font];
    
    //7.地址
    self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelX, (labelH+margginY)*3, self.detailLabel.frame.size.width-labelX*2+9, labelH+10)];
    [self.detailLabel addSubview:self.addressLabel];
    self.addressLabel.text = [NSString stringWithFormat:@"地址：浙江省杭州市西湖区西溪科创元11庄202室"];
    self.addressLabel.numberOfLines = 0;
    [self.addressLabel sizeToFit];
    self.addressLabel.textColor = UIColorWithRGBA(248, 162, 51, 1);
    self.addressLabel.font = [UIFont boldSystemFontOfSize:font];
}

//- (void)initWithLabel:(UILabel *)label  andWithFrame:(CGRect)frame andWithText:(NSString *)text andWithTextColor:(UIColor *)color
//{
//    label.frame = frame;
//    label.text = text;
//    label.textColor = color;
//    
//}
#pragma  mark 更换收货地址 按钮
- (void)editAddress
{
    if ([self.delegate respondsToSelector:@selector(changeAddressButton)]) {
        [self.delegate changeAddressButton];
    }
}
@end
